#include "interrupt.h"
#include "task.h"
#include "mutex.h"

extern volatile Task* gCTaskAddr;

void TimerHandler()
{
    static uint i = 0;

    i = (i + 1) % 5;

    if ( i == 0) {
        Schedule();
    }
    
    SendEOI(MASTER_EOI_PORT);
}

void SysCallHandler(uint type, uint cmd, uint param1, uint parma2)  // __cdecl__
{
    switch (type) {
        case 0:
            KillTask();
            break;
        case 1:
            MutexCallHandler(cmd, param1);
            break;
        default:
            break;
    }
}

void PageFaultHandler()
{
    SetPrintPos(0, 6);
    PrintString("Page Fault: kill ");
    PrintString(gCTaskAddr->name);

    KillTask();
}

void SegmentFaultHandler()
{
    SetPrintPos(0, 6);
    PrintString("Segment Fault: kill ");
    PrintString(gCTaskAddr->name);

    KillTask();
}

